package elevatronic.view;

import javax.swing.JFrame;

import elevatronic.models.Building;
import elevatronic.view.left.LeftPanel;
import elevatronic.view.right.RightPanel;
import elevatronic.view.simulation.BuildingView;
import elevatronic.view.simulation.SimulationPanel;

/**
 * 
 * @author Benjamin CORNEC
 * This class is used to manage all the view of the app
 * it's the window of the application
 */

public class MainFrame extends JFrame{
	//id of the class
	private static final long serialVersionUID = -1184811019633148474L;
	
	//<resolution of the application>
	public static final int LEFT_PANEL_WIDTH=200;
	public static final int LEFT_PANEL_POSX=0;
	public static final int SIMULATION_PANEL_WIDTH=800;
	public static final int SIMULATION_PANEL_POSX=LEFT_PANEL_POSX+LEFT_PANEL_WIDTH;
	public static final int RIGHT_PANEL_WIDTH=218;
	public static final int RIGHT_PANEL_POSX=SIMULATION_PANEL_POSX+SIMULATION_PANEL_WIDTH;
	public static final int WIDTH=LEFT_PANEL_WIDTH+SIMULATION_PANEL_WIDTH+RIGHT_PANEL_WIDTH;
	public static final int HEIGHT=800;
	public static final int WINDOW_BORDER=40;
	//</resolution of the application>
	
	//the building view attached to the building model
	private BuildingView buildingView;
	public BuildingView getBuildingView() {
		return buildingView;
	}
	public void setBuildingView(BuildingView buildingView) {
		this.buildingView = buildingView;
	}
	
	//the view of the world
	private SimulationPanel simulationPanel;
	public SimulationPanel getSimulationPanel() {
		return simulationPanel;
	}
	public void setSimulationPanel(SimulationPanel worldView) {
		this.simulationPanel = worldView;
	}

	//the view of the right panel
	private RightPanel rightPanel;
	public RightPanel getRightPanel() {
		return rightPanel;
	}
	public void setRightPanel(RightPanel rightPanel) {
		this.rightPanel = rightPanel;
	}
	
	//the view of the left panel
	private LeftPanel leftPanel;
	public LeftPanel getLeftPanel() {
		return leftPanel;
	}
	public void setLeftPanel(LeftPanel leftPanel) {
		this.leftPanel = leftPanel;
	}
	
	

	/**
	 * Constructor 
	 * @param building building (the only one) instance of the app
	 */
	public MainFrame(Building building){
		//if someone close the window, all the application shutdown
	    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	    //the title of the window
		this.setTitle("Elevatronic");
		//setting the resolution
	    this.setSize(WIDTH, HEIGHT+WINDOW_BORDER);
	    //setting the mapping of object in the window
	    this.setLocationRelativeTo(null);
	    setLayout(null);
	    
	    //create the building view
	    buildingView=new BuildingView(building);
	    setSimulationPanel(new SimulationPanel(getBuildingView(),SIMULATION_PANEL_WIDTH,HEIGHT));
	    getSimulationPanel().setBounds(SIMULATION_PANEL_POSX,0,SIMULATION_PANEL_WIDTH,HEIGHT);
	    add(getSimulationPanel());

	    setRightPanel(new RightPanel(RIGHT_PANEL_WIDTH,HEIGHT));
	    getRightPanel().setBounds(RIGHT_PANEL_POSX, 0, RIGHT_PANEL_WIDTH, HEIGHT);
	    add(getRightPanel());
	    
	    setLeftPanel(new LeftPanel(LEFT_PANEL_WIDTH,HEIGHT,buildingView));
	    getLeftPanel().setBounds(LEFT_PANEL_POSX, 0, LEFT_PANEL_WIDTH, HEIGHT);
	    add(getLeftPanel());
	    
	    this.setVisible(true);
	}
	
	//iterative method
	public void update(int step){
		getSimulationPanel().update(step);
		getLeftPanel().update(step);
		getRightPanel().update(step);
	}
	
	
	
}
